package top.minuy.algorithm.search.binary;

import top.minuy.util.generate.ArrayGenerator;

/**
 * 二分搜索算法测试
 *
 * @author Minuy
 * @time 13:52
 * @date 2021/9/2
 */
public class Test {
    public static void main(String[] args) {

        Integer[] arr = ArrayGenerator.generateOrderedArray(10);
        if (arr.length < 100) {
            for (int i : arr) {
                System.out.print(i + " ");
            }
        }
        System.out.println();
        int index = BinarySearch.search(arr, 10);
        System.out.println("index = " + index);

        Integer[] data = {-1, 3, 6, 7, 7, 7, 9, 10, 12};
        index = BinarySearch.upper(data, -6);
        String val = "null";
        if (index >= 0 && index < data.length) {
            val = data[index] + "";
        }
        System.out.println("upper = " + index + " val = " + val);

        Integer[] data1 = {-1, 3, 6, 7, 7, 7, 9, 10, 12};
        index = BinarySearch.up_ceil(data1, 7);
        val = "null";
        if (index >= 0 && index < data1.length) {
            val = data1[index] + "";
        }
        System.out.println("up_ceil = " + index + " val = " + val);

        Integer[] data2 = {-1, 3, 6, 7, 7, 7, 9, 10, 12};
        index = BinarySearch.lower_ceil(data2, 7);
        val = "null";
        if (index >= 0 && index < data2.length) {
            val = data2[index] + "";
        }
        System.out.println("lower_ceil = " + index + " val = " + val);

        Integer[] data3 = {-1, 3, 6, 7, 9, 10, 12};
        index = BinarySearch.lower(data3, 14);
        val = "null";
        if (index >= 0 && index < data3.length) {
            val = data3[index] + "";
        }
        System.out.println("lower = " + index + " val = " + val);
    }
}
